var myGrid;
$(function() {
	myGrid = jQuery("#list").jqGrid({
		url : "workflow/process/process!datalist",
		datatype : "json",
		mtype : 'GET',
		colNames : [ 
		             '流程名', 
		             '变量设置', 
		             '服务设置',
		             //'人员设置',
		             '管理'],
		colModel : [ {
			name : 'workflowName',
			index : 'workflowName',
			width : 300
			
		}, {
			name : 'workflowName',
			index : 'workflowName',
			width : 50,
			formatter:tplFormatter
		}, 
		/*{
			name : 'workflowName',
			index : 'workflowName',
			width : 50,
			formatter:tplFormatter2
		},*/
		
		{
			name : 'workflowName',
			index : 'workflowName',
			width : 50,
			formatter:tplFormatter3
		}, {
			name : 'workflowName',
			index : 'workflowName',
			width : 50,
			formatter:deleteFormatter
		}		
		],
		pager : '#pager',
		rowNum : 10,
		rowList : [ 10, 20, 30 ],
		sortname : 'name',
		sortorder : 'desc',
		viewrecords : true,
		caption : '所有流程',
		width : '750',
		height : '300',
		jsonReader : {
			repeatitems : false,
			id : "0"
		}
	});
	myGrid.jqGrid("navGrid", "#pager", {
		edit : false,
		add : false,
		del : false,
		search : false
	});
	myGrid.jqGrid("navButtonAdd", "#pager", {
		onClickButton : function() {
			addNewWorkflow();
		},
		buttonicon : "ui-icon-newwin",
		caption : "添加新流程",
		id : "newGroup"
	});	
});
function tplFormatter(cv, opt, row) {
	var link2=$("<a href='javascript:;' onclick='userSettings(\""+cv+"\");'>变量设置</a>");
	return $("<span></span>").append(link2).html();
}

function tplFormatter2(cv, opt, row) {
	var link4=$("<a href='javascript:;' onclick='actionSettings(\""+cv+"\");'>服务设置</a>");
	return $("<span></span>").append(link4).html();
}
function tplFormatter3(cv, opt, row) {
	var link3=$("<a href='javascript:;' onclick='processSettings(\""+cv+"\");'>人员设置</a>");
	return $("<span></span>").append(link3).html();
}

function deleteFormatter(cv,opt,row){
	var link=$("<a href='javascript:;' onclick='removeWorkflow(\""+cv+"\");'>删除</a>");
	return $('<span></span>').append(link).html();
}

function showFormatter(cv,opt,row){
	var link=$("<a href='javascript:;' onclick='modifyWorkflow(\""+cv+"\");'>修改</a>");
	return $('<span></span>').append(link).html();
}

function addNewWorkflow() {
	doGet("workflow/process/edit");
}
function removeWorkflow(name){
	var p = {"bean.workflowName":name};
	$.ajax({
		"type":"post",
		"url":"workflow/process/process!remove",
		"data":$.param(p),
		"success":function(){
			myGrid.trigger("reloadGrid");
		},
		"error":function(msg){
			createNotify("删除错误!"+msg);
		}
	});
}
function processSettings(cv){
	var url = "workflow/process/process!getbyname";
	doPost(url,{
		"bean.workflowName":cv
	});
}
function userSettings (cv) {
    var url = "variablesetting/variable-setting!byworkflow";
    var data="workflowPk="+cv;
    doPost(url,data);
}
function actionSettings(cv){
	var url = "systemservicesetting/system-service-setting!byworkflow";
    var data="workflowPk="+cv;
    doPost(url,data);
}
function modifyWorkflow(cv){
	var url = "workflow/process/process!show";
    var data="bean.workflowName="+cv;
    doPost(url,data);
}